home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / prints.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  1.1 KB  |  53 lines

  1. #define __SRC__
  2. #include <stdio.h>
  3. #include "lib.h"
  4. /* prints() is like printf(), except that it can only handle %s and %c.  It
  5.  * cannot print any of the numeric types such as %d, %o, etc.  It has the
  6.  * advantage of not requiring the runtime code for converting binary numbers
  7.  * to ASCII, which saves 1K bytes in the object program.  Since many of the
  8.  * small utilities do not need numeric printing, they all use prints.
  9.  */
  10. #define    GETARG(typ)    *((typ *)valp)++
  11.  
  12. void prints(s, arglist)
  13. _CONST register char *s;
  14. char *arglist;
  15. {
  16.   register w;
  17.   int k, *valp;
  18.   char *p, *p1, c;
  19.  
  20.   valp = (int *)  &arglist;
  21.  
  22.   while (*s != '\0') {
  23.     if (*s !=  '%') {
  24.         putchar(*s++);
  25.         continue;
  26.     }
  27.  
  28.     w = 0;
  29.     s++;
  30.     while (*s >= '0' && *s <= '9') {
  31.         w = 10 * w + (*s - '0');
  32.         s++;
  33.     }
  34.  
  35.  
  36.     switch(*s) {
  37.          case 'c':    k = GETARG(int); putchar(k); s++; continue;
  38.  
  39.         case 's':
  40.                   p = (GETARG(char *));
  41.  
  42.             p1 = p;
  43.             while(c = *p++) putchar(c); s++;
  44.             if ( (k = w - ((int)(p-p1)-1)) > 0) while (k--) putchar(' ');
  45.             continue;
  46.         default:    putchar('%'); putchar(*s++); continue;
  47.     }
  48.  
  49.   }
  50. }
  51.  
  52.  
  53.